home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 039a / netpq203.zip / NETPQ.C < prev    next >
Text File  |  1993-03-18  |  7KB  |  327 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4.  
  5. #include "nos.h"
  6. #include "noslib.h"
  7. #include "netpq.h"
  8. #include "version.h"
  9. #include "proto.h"
  10.  
  11. //
  12. //  NETPQ.EXE
  13. //
  14. //  See Usage () for comments
  15. //
  16. //  This program uses the Borland C versions of the nos library included in
  17. //  the file 'book.zip' on the Artisoft BBS (602-293-0065) and was compiled
  18. //  using Borland C++.
  19. //
  20. //  Written by Alan R. Roney
  21. //
  22. //  Released into the public domain by the author.  The author accepts no
  23. //  responsiblity for any problems associated with use of this program.
  24. //
  25. //  This software is not to be included in any "for profit" software packages.
  26. //
  27. //  You are welcome to modify the source code for this program.  Please
  28. //  forward a copy of your changes to the author.
  29. //
  30. //  Comments and suggested changes should be directed to the author at:
  31. //
  32. //        Compuserve:     76330,3711
  33. //        Internet:        76330.3711@compuserve.com
  34. //        Artisoft:        alan roney
  35. //
  36.  
  37.  
  38. struct serverdef *server;
  39. struct localqueuedef *localqueue;
  40.  
  41. int currentserver, adaptornum, numberoflogins, currentprinter, found;
  42. int queuejobcount, printjobcount;
  43. int maxlocalqueuecount, localqueuecount, previouslocalqueuecount;
  44. int monoflag;
  45. int plotterflag;
  46. int timeout;
  47.  
  48.  
  49. char    servername [D_NAMESZ + 2];
  50.  
  51. struct PS serverps;
  52. struct queue_entry serverqe;
  53. struct time_block servertime;
  54. struct user_account serveraccount;
  55.  
  56.  
  57. void main (int argc, char *argv [])
  58.     {
  59.     int keypressed, i, j;
  60.     int show_title;
  61.     char buf [50];
  62.  
  63.     monoflag = false;
  64.     plotterflag = false;
  65.     show_title = true;
  66.  
  67.  
  68.     for (i = 1; i < argc; i++)
  69.     {
  70.     if ( (argv [i] [0] == '-') || (argv [i] [0] == '/') )
  71.         {
  72.         for (j = 1; argv [i] [j] != '\0' ; j++)
  73.         {
  74.         switch (argv [i] [j])
  75.             {
  76.             case 'm':
  77.             case 'M':
  78.             monoflag = true;
  79.             break;
  80.  
  81.             case 'p':
  82.             case 'P':
  83.             plotterflag = true;
  84.             break;
  85.  
  86.             case 'h':
  87.             case 'H':
  88.             case '?':
  89.             Usage ();
  90.             exit ();
  91.             break;
  92.  
  93.             }
  94.         }
  95.         }
  96.     }
  97.  
  98.     setup ();
  99.  
  100.     timeout = NUM_UPDATES_FOR_TIMEOUT;
  101.     previouslocalqueuecount = 0;
  102.  
  103.     do
  104.     {
  105.     do
  106.         {
  107.         getserverinfo ();
  108.         clrscr ();
  109.         reportinfo ();
  110.         showmenu ();
  111.  
  112.         if (show_title)
  113.         {
  114.         sprintf (buf, "NETPQ.EXE   Version %d.%02d\0", MAJOR_VERSION, MINOR_VERSION);
  115.         message (buf, false);
  116.         show_title = false;
  117.         }
  118.  
  119.         if (localqueuecount != previouslocalqueuecount)
  120.         {
  121.         timeout = NUM_UPDATES_FOR_TIMEOUT;
  122.         previouslocalqueuecount = localqueuecount;
  123.         }
  124.  
  125.         timeout--;
  126.  
  127.         i = 0;
  128.         while (i++ < 2)
  129.         {
  130.         sleep (1);
  131.         if (kbhit () != 0)
  132.             break;
  133.         }
  134.         }while ( (kbhit () == 0) && (timeout > 0) );
  135.  
  136.     if (timeout <= 0)
  137.         break;
  138.  
  139.     keypressed = getextch ();
  140.  
  141.     switch (keypressed)
  142.         {
  143.         case key_f1:
  144.         f1keypressed ();
  145.         timeout = NUM_UPDATES_FOR_TIMEOUT;
  146.         break;
  147.  
  148.         case key_f2:
  149.         f2keypressed ();
  150.         timeout = NUM_UPDATES_FOR_TIMEOUT;
  151.         break;
  152.  
  153.         case key_f3:
  154.         if (plotterflag)
  155.             {
  156.             f3keypressed ();
  157.             timeout = NUM_UPDATES_FOR_TIMEOUT;
  158.             break;
  159.             }
  160.  
  161.         default:
  162.         keypressed = key_esc;
  163.         break;
  164.         }
  165.     lowvideo ();
  166.  
  167.     }while (keypressed != key_esc);
  168.  
  169.     lowvideo ();
  170.     textcolor (LIGHTGRAY);
  171.     clrscr ();
  172.  
  173.     free (server);
  174.     free (localqueue);
  175.     }
  176.  
  177.  
  178. void setup ()
  179.     {
  180.     char *plotterserver = plotterserverstring;
  181.     int i;
  182.  
  183.     //    Check for presence of NOS Version 4.0 or greater
  184.  
  185.     if (NOSPresence () == -1)
  186.     {
  187.     printf ("NOS not installed\n");
  188.     exit (1);
  189.     }
  190.  
  191.     if (NOSGetVersion () < NOS_VERSION)
  192.     {
  193.     printf ("Incorrect NOS Version\n");
  194.     exit (1);
  195.     }
  196.  
  197.     //    Find out how many servers this node is logged into
  198.  
  199.     numberoflogins = 0;
  200.     servername [0] = servername [1] = '\\';
  201.  
  202.     while (NOSGetLogin (&numberoflogins, &servername [2], &adaptornum) != -1)
  203.     numberoflogins++;
  204.  
  205.     if (numberoflogins <= 0)
  206.     {
  207.     printf ("Not logged into to any servers\a\n");
  208.     exit (1);
  209.     }
  210.  
  211.     //    open structures for storing information
  212.  
  213.     if ( (server = (struct serverdef *) calloc (numberoflogins, sizeof (struct serverdef))) ==    (struct serverdef *) 0)
  214.     {
  215.     printf ("Couldn't allocate space for server information\n");
  216.     exit (1);
  217.     }
  218.  
  219.     maxlocalqueuecount = 0;
  220.     if ( (localqueue = (struct localqueuedef *) calloc (1, sizeof (struct localqueuedef))) ==  (struct localqueuedef *) 0)
  221.     {
  222.     printf ("Couldn't allocate space for queue information\n");
  223.     exit (1);
  224.     }
  225.  
  226.     //    Get server names and queue privileges
  227.  
  228.     currentserver = 0;
  229.     i = 0;
  230.  
  231.     while (currentserver < numberoflogins)
  232.     {
  233.     if (NOSGetLogin (¤tserver, &servername [2], &adaptornum) == -1)
  234.         {
  235.         NOSperror ("NOSGetLogin");
  236.         exit (1);
  237.         }
  238.  
  239.     if (
  240.        (!plotterflag) ||
  241.        (strcmp (servername, plotterserver) == 0)
  242.        )
  243.         {
  244.         strcpy (server [i] .servername, servername);
  245.  
  246.         //    Check for queue privileges
  247.  
  248.         if (NOSGetAccount (&serveraccount, servername) == -1)
  249.         {
  250.         NOSperror ("NOSGetAccount");
  251.         exit (1);
  252.         }
  253.         else
  254.         {
  255.         if (((serveraccount .UA_privilege & UA_privilege_superACL) != 0) ||
  256.             ((serveraccount .UA_privilege & UA_privilege_superqueue) != 0))
  257.             {
  258.             server [i] .queue_privilege = true;
  259.             }
  260.         else
  261.             server [i] .queue_privilege = false;
  262.         }
  263.         i++;
  264.         }
  265.  
  266.     currentserver++;
  267.     }
  268.  
  269.     qsort ( (void *) server, i, sizeof (struct serverdef), comparestring);
  270.  
  271.     numberoflogins = i;
  272.  
  273.     }
  274.  
  275.  
  276. void showmenu ()
  277.     {
  278.     textcolor (LIGHTGRAY);
  279.     highvideo ();
  280.     cprintf ("F1: ");
  281.     lowvideo ();
  282.     cprintf ("Control Port  ");
  283.  
  284.     highvideo ();
  285.     cprintf ("F2: ");
  286.     lowvideo ();
  287.     cprintf ("Control Queue  ");
  288.  
  289.     if (plotterflag)
  290.     {
  291.     highvideo ();
  292.     cprintf ("F3: ");
  293.     lowvideo ();
  294.     cprintf ("Release Plot File  ");
  295.     }
  296.  
  297.     highvideo ();
  298.     cprintf ("Any other key: ");
  299.     lowvideo ();
  300.     cprintf ("Exit");
  301.     }
  302.  
  303.  
  304.  
  305. void Usage ()
  306.     {
  307.     int i;
  308.  
  309.     printf ("\nNETPQ.EXE   Version");
  310.     printf (" %d.%02d", MAJOR_VERSION, MINOR_VERSION);
  311.     i = BETA_VERSION;
  312.     if (i > 0)
  313.     printf (".%02d", BETA_VERSION);
  314.     printf ("\n\n");
  315.  
  316.     printf ("Displays printer queue activity on all logged on servers.  The display\n");
  317.     printf ("    updates every two seconds.  Queued files may be cancelled, held, or\n");
  318.     printf ("    released by the operator.  If the operator has queue privileges, the\n");
  319.     printf ("    operator can change the downloading status of each printer port and\n");
  320.     printf ("    may 'rush' queued files.\n\n");
  321.     printf ("If you are using a monochrome monitor, you may need to use the /m\n");
  322.     printf ("    switch to inhibit color selections.\n\n");
  323.     printf ("The /p switch allows the operator to view and release files destined\n");
  324.     printf ("    for %s%s\n\n", plotterserverstring, plotterstring);
  325.  
  326.     }
  327.